var init = {
	'1':'交易对象',
	'2':'交易频率',
	'3':'交易额度',
	'4':'流失状态'
};
//服务器传过来的数据
var obj = {
	id:'1',
	pid:'0',
	name:'刘璐',
	sendobj:'1',
	sendobjChild:['老客户'],
	sendtime:'立刻',
	sendtimeChild:'',
	sendmethod:['邮件'],
	rules:'参加上级活动',
	children:[
		{
			id:'1_1',
			pid:'1',
			name:'刘璐1',
			sendobj:'1',
			sendobjChild:['老客户'],
			sendtime:'立刻',
			sendtimeChild:'',
			sendmethod:['短信','邮件'],
			rules:'参加上级活动',
			children:[
			]
		},
		{
			id:'1_2',
			pid:'1',
			name:'刘璐2',
			sendobj:'1',
			sendobjChild:['老客户'],
			sendtime:'立刻',
			sendtimeChild:'',
			sendmethod:['短信'],
			rules:'参加上级活动',
			children:[]
		},
		{
			id:'1_2',
			pid:'1',
			name:'刘璐2',
			sendobj:'1',
			sendobjChild:['老客户'],
			sendtime:'立刻',
			sendtimeChild:'',
			sendmethod:['短信'],
			rules:'参加上级活动',
			children:[]
		}
	]
};
$(function(){
	app.module(obj);//服务器传来数据后，调用此方法
	$(".info-hover").mouseenter(function(){
	    $(this).next().show();
	});
	$(".info-hover").mouseleave(function(){
	    $(this).next().hide();
	});
});

var app = {
	node:function(obj){
		var children = obj.children;
		var topLine = '';
		var item = '';
		var sendtime = obj.children[0].sendtimeChild?obj.children[0].sendtimeChild:obj.children[0].sendtime;
		if(children.length == 2){
			if(obj.children[1].rules == '无' || !obj.children[1].rules){
				topLine = '<div class="top-line">'+
						'</div>';
			}else{
				topLine = '<div class="top-line">'+
							'<div class="prism" style="top: -31px;left: 100px;">'+obj.children[1].rules+'</div>'+
						'</div>';
			}
			item = this.nodeitem(obj.children[1]);
			
		}else if (children.length > 2) {
			for (var i = 1; i < children.length; i++) {
				if(i == 1){
					if(obj.children[i].rules == '无' || !obj.children[i].rules){
						topLine += '<div class="top-line">'+
								'</div>';
					}else{
						topLine += '<div class="top-line">'+
									'<div class="prism" style="top: -31px;left: 100px;">'+obj.children[i].rules+'</div>'+
								'</div>';
					}
				}else{
					if(obj.children[i].rules == '无'){
						topLine += '<div class="top-line" style="width:320px;">'+
								'</div>';
					}else{
						topLine += '<div class="top-line" style="width:320px;">'+
									'<div class="prism" style="top: -31px;left: 100px;">'+obj.children[i].rules+'</div>'+
								'</div>';
					}
				}
				
				item += this.nodeitem(obj.children[i]);
			}
		}
		
		return '<div class="pad2">'+
				'<div class="item-bottom top-title">'+
					'<p>1、拉新模型</p>'+
					'<div>'+
						'<label class="radio" style="display:inline-block;margin: 0 10px;">'+
						    '<input type="checkbox" name="firstpage" value="1" style="margin:0;">'+
						    '首页显示'+
						'</label>'+
						'<a href="javascript:;">编辑</a>'+
						'<a href="javascript:;">启用</a>'+
						'<a href="javascript:;">复制</a>'+
						'<a href="javascript:;">删除</a>'+
					'</div>'+
				'</div>'+
				'<div style="padding:35px 0 10px;">'+
					'<div style="display:flex;">'+
						topLine+
					'</div>'+
					'<div style="display:flex;">'+
						'<div class="item-block bg1 model-height">'+
							obj.name+
							'<div class="model-con">'+
								'<p>打开次数：<span>1000</span></p>'+
								'<p>转发次数：<span>100</span></p>'+
								'<p>提交表单数：<span>1000</span></p>'+
								'<p>核销人数：<span>10</span></p>'+
								'<p>累计消费金额：<span>1000</span></p>'+
							'</div>'+
							'<div class="info-hover"></div>'+
							'<ul>'+
								'<li>发送方式：<span>'+obj.sendmethod.join(',')+'</span></li>'+
								'<li>'+init[obj.sendobj]+'：<span>'+obj.sendobjChild.join(',')+'</span></li>'+
								'<li>发送时间：<span>'+obj.sendtime+obj.sendtimeChild+'</span></li>'+
							'</ul>'+
						'</div>'+
						'<div class="item-block line-block" style="height:70px;">'+
							'<div class="prism" style="top:39px;">'+obj.children[0].rules+'</div>'+
						'</div>'+
						'<div class="item-block bg2 model-height">'+
							obj.children[0].name+
							'<div class="date date-left" style="top:53px;">'+sendtime+'</div>'+
							'<div class="model-con">'+
								'<p>打开次数：<span>1000</span></p>'+
								'<p>转发次数：<span>100</span></p>'+
								'<p>提交表单数：<span>1000</span></p>'+
								'<p>核销人数：<span>10</span></p>'+
								'<p>累计消费金额：<span>1000</span></p>'+
							'</div>'+
							'<div class="info-hover"></div>'+
							'<ul>'+
								'<li>发送方式：<span>'+obj.children[0].sendmethod.join(',')+'</span></li>'+
								'<li>'+init[obj.children[0].sendobj]+'：<span>'+obj.children[0].sendobjChild.join(',')+'</span></li>'+
								'<li>发送时间：<span>'+obj.children[0].sendtime+obj.children[0].sendtimeChild+'</span></li>'+
							'</ul>'+
						'</div>'+
						item+
					'</div>'+
				'</div>'+
			'</div>';
	},
	nodeitem:function(data){
		var sendtime = data.sendtimeChild?data.sendtimeChild:data.sendtime;
		var html = '<div class="item-block"></div>'+
					'<div class="item-block bg3 model-height">'+
						data.name+
						'<div class="date">'+sendtime+'</div>'+
						'<div class="model-con">'+
							'<p>打开次数：<span>1000</span></p>'+
							'<p>转发次数：<span>100</span></p>'+
							'<p>提交表单数：<span>1000</span></p>'+
							'<p>核销人数：<span>10</span></p>'+
							'<p>累计消费金额：<span>1000</span></p>'+
						'</div>'+
						'<div class="info-hover"></div>'+
						'<ul>'+
							'<li>发送方式：<span>'+data.sendmethod.join(',')+'</span></li>'+
							'<li>'+init[data.sendobj]+'：<span>'+data.sendobjChild.join(',')+'</span></li>'+
							'<li>发送时间：<span>'+data.sendtime+data.sendtimeChild+'</span></li>'+
						'</ul>'+
					'</div>';
		return html;

	},
	module:function(data){
		if(data.children.length > 0){
			$('#module').append(app.node(data));
			for(var i = 0; i < data.children.length; i ++){
				this.module(data.children[i]);
			}
		}
	}
};

//展示模块
function module(data){
	
}


